#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
int main(){
    pid_t ret = fork();
    if(ret == -1){
        return -1;
    }else if(ret == 0){
        //child
        //printf("I am child,pid = %d ppid= %d\n",getpid(),getppid());
        int* p = NULL;
        *p = 1;
        exit(99);
    }else{
        //father
        printf("I am father,pid = %d,ppid = %d\n",getpid(),getppid());
        int status = 0;
        int ret = wait(&status);
        if(ret == -1){
            return -1;
        }else if (ret > 0 && ((status & 0x7f) == 0)){
            //子进程正常退出
            printf("child process return code is %d\n",(status >> 8)&0xff);
        }else{
            //异常退出
            printf("child process receive signal is %d,coredump flag is %d\n",status&0x7f,(status>>7)&0x1);
        }
    }
    return 0;
}
